% Remember to use the lgrind style

\Head{}
\File{./java/DirectionsFrame.java}{2006}{4}{27}{19:09}{5366}
\L{\LB{\C{}/*}}
\L{\LB{_*_DirectionsFrame.java}}
\L{\LB{_*}}
\L{\LB{_*_Created_on_January_8,_2006,_5:45_PM}}
\L{\LB{_*/\CE{}}}
\L{\LB{}}
\L{\LB{\C{}//http://java.sun.com/developer/techDocs/hi/repository/TBG\_Navigation.html\CE{}}}
\L{\LB{\C{}//http://java.sun.com/docs/books/tutorial/uiswing/components/toolbar.html\CE{}}}
\L{\LB{\C{}//http://java.sun.com/docs/books/tutorial/uiswing/components/scrollpane.html\CE{}}}
\L{\LB{}}
\L{\LB{\K{package}_\V{project01};}}
\L{\LB{}}
\L{\LB{\K{import}_\V{javax}.\V{swing}.*;}}
\L{\LB{\K{import}_\V{javax}.\V{swing}.\V{event}.*;}}
\L{\LB{\K{import}_\V{java}.\V{awt}.*;}}
\L{\LB{\K{import}_\V{java}.\V{awt}.\V{event}.*;}}
\L{\LB{\K{import}_\V{java}.\V{util}.*;}}
\L{\LB{}}
\L{\LB{}}
\L{\LB{}}
\L{\LB{\C{}/**}}
\L{\LB{_*_Frame_responsible_for_stepping_user_through_point-to-point_directions.}}
\L{\LB{_*}}
\L{\LB{_*_\CE{}\V{author}_\V{Ian}_\V{Melnick}}}
\L{\LB{\C{}*/\CE{}}}
\L{\LB{\K{public}_\K{class}_\V{DirectionsFrame}_\{}}
\L{\LB{}\Tab{4}{\V{JFrame}_\V{window};}}
\L{\LB{}\Tab{4}{\V{JTextArea}_\V{directionBox};}}
\L{\LB{}\Tab{4}{\K{int}_\V{curDirection};}}
\L{\LB{}\Tab{4}{\V{String}_\V{curMap};}}
\L{\LB{}\Tab{4}{\V{JScrollPane}_\V{scrollPane};}}
\L{\LB{}\Tab{4}{\V{JToolBar}_\V{toolBar};}}
\L{\LB{}\Tab{4}{\V{JButton}_\V{bPrevious},_\V{bNext};}}
\L{\LB{}\Tab{4}{\V{Dijkstra}_\V{d};}}
\L{\LB{}\Tab{4}{\V{MapComponent}.\V{MapManager}_\V{mm};}}
\L{\LB{}\Tab{4}{\V{LinkedList}\<\V{NodeItem}\>_\V{r};}}
\L{\LB{}\Tab{4}{\V{Router}_\V{router};}}
\L{\LB{}\Tab{4}{}}
\L{\LB{}\Tab{4}{\C{}/**_Creates_a_new_instance_of_DirectionsFrame_*/\CE{}}}
\index{DirectionsFrame}\Proc{DirectionsFrame}\L{\LB{}\Tab{4}{\K{public}_\V{DirectionsFrame}(\V{Router}_\V{router},_\V{Dijkstra}_\V{d})_\{}}
\L{\LB{}\Tab{8}{\K{this}.\V{d}_=_\V{d};}}
\L{\LB{}\Tab{8}{\K{this}.\V{router}_=_\V{router};}}
\L{\LB{}\Tab{8}{\K{this}.\V{mm}_=_\V{router}.\V{getMapManager}();}}
\L{\LB{}\Tab{8}{\V{ButtonMethods}_\V{bm}_=_\K{new}_\V{ButtonMethods}();}}
\L{\LB{}\Tab{8}{\V{curDirection}_=_\N{0};}}
\L{\LB{}\Tab{8}{\V{curMap}_=_\V{router}.\V{getMap}();}}
\L{\LB{}\Tab{8}{}}
\L{\LB{}\Tab{8}{\V{window}_=_\K{new}_\V{JFrame}(\S{}\3Steps\3\SE{});}}
\L{\LB{}\Tab{8}{\V{window}.\V{setLayout}(\K{new}_\V{BorderLayout}());}}
\L{\LB{}\Tab{8}{\V{window}.\V{setDefaultCloseOperation}(\V{JFrame}.\V{DISPOSE\_ON\_CLOSE});}}
\L{\LB{}\Tab{16}{}}
\L{\LB{}\Tab{8}{\V{bPrevious}_=_\K{new}_\V{JButton}();}}
\L{\LB{}\Tab{12}{\V{bPrevious}.\V{setActionCommand}(\S{}\3previous\3\SE{});}}
\L{\LB{}\Tab{12}{\V{bPrevious}.\V{setToolTipText}(\S{}\3Previous_Instruction\3\SE{});}}
\L{\LB{}\Tab{12}{\V{bPrevious}.\V{addActionListener}(\V{bm});}}
\L{\LB{}\Tab{12}{\V{bPrevious}.\V{setText}(\S{}\3\<\<\3\SE{});}}
\L{\LB{}\Tab{8}{}}
\L{\LB{}\Tab{8}{\V{bNext}_=_\K{new}_\V{JButton}();}}
\L{\LB{}\Tab{12}{\V{bNext}.\V{setActionCommand}(\S{}\3next\3\SE{});}}
\L{\LB{}\Tab{12}{\V{bNext}.\V{setToolTipText}(\S{}\3Next_Instruction\3\SE{});}}
\L{\LB{}\Tab{12}{\V{bNext}.\V{addActionListener}(\V{bm});}}
\L{\LB{}\Tab{12}{\V{bNext}.\V{setText}(\S{}\3\>\>\3\SE{});}}
\L{\LB{}}
\L{\LB{}\Tab{8}{\V{toolBar}_=_\K{new}_\V{JToolBar}(\S{}\3Navigation\3\SE{});}}
\L{\LB{}\Tab{8}{\V{toolBar}.\V{add}(\V{bPrevious});}}
\L{\LB{}\Tab{8}{\V{toolBar}.\V{add}(\V{bNext});}}
\L{\LB{}\Tab{8}{}}
\L{\LB{}\Tab{8}{\V{directionBox}_=_\K{new}_\V{JTextArea}();}\Tab{44}{\C{}//10,_30\CE{}}}
\L{\LB{}\Tab{8}{\V{directionBox}.\V{setEditable}(\K{false});}\Tab{47}{}}
\L{\LB{}\Tab{8}{\V{scrollPane}_=_\K{new}_\V{JScrollPane}(\V{directionBox});}}
\L{\LB{}\Tab{8}{}}
\L{\LB{}\Tab{8}{\V{window}.\V{add}(\V{toolBar},_\V{BorderLayout}.\V{NORTH});}}
\L{\LB{}\Tab{8}{\V{window}.\V{add}(\V{scrollPane},_\V{BorderLayout}.\V{SOUTH});}}
\L{\LB{}\Tab{8}{}}
\L{\LB{}}
\L{\LB{}\Tab{8}{\V{d}.\V{run}();}}
\L{\LB{}\Tab{8}{\V{r}_=_\V{d}.\V{getRoute}();}}
\L{\LB{}\Tab{8}{\V{showDirections}(\V{curDirection});}}
\L{\LB{}\Tab{8}{\V{d}.\V{reset}();}}
\L{\LB{}\Tab{8}{}}
\L{\LB{}\Tab{16}{}}
\L{\LB{}\Tab{8}{\V{window}.\V{pack}();}}
\L{\LB{}\Tab{8}{\V{window}.\V{setVisible}(\K{true});}}
\L{\LB{}\Tab{4}{\}}}
\L{\LB{}\Tab{4}{}}
\L{\LB{}}
\index{showDirections}\Proc{showDirections}\L{\LB{}\Tab{4}{\K{private}_\K{void}_\V{showDirections}(\K{int}_\V{curDirectionNumber})_\{}}
\L{\LB{}\Tab{8}{\V{directionBox}.\V{setText}(\K{null});}}
\L{\LB{}\Tab{8}{\V{NodeItem}_\V{prvNode},_\V{curNode},_\V{nxtNode};}}
\L{\LB{}\Tab{8}{\K{for}(\K{int}_\V{i}=\N{0};_\V{i}\<\V{r}.\V{size}();_\V{i}++)_\{}}
\L{\LB{}\Tab{12}{\K{if}(\V{i}==\N{0})}\Tab{36}{\V{directionBox}.\V{append}(\S{}\3Start_at:\2t\3\SE{});}}
\L{\LB{}\Tab{12}{\K{else}_\K{if}(\V{i}==\V{r}.\V{size}()\-\N{1})}\Tab{36}{\V{directionBox}.\V{append}(\S{}\3End_at:\2t\3\SE{});}}
\L{\LB{}\Tab{12}{\K{else}}\Tab{36}{\V{directionBox}.\V{append}(\S{}\3Go_to:\2t\3\SE{});}}
\L{\LB{}\Tab{12}{}}
\L{\LB{}\Tab{12}{\K{if}(\V{i}\<\V{r}.\V{size}()\-\N{1})}\Tab{36}{\V{nxtNode}_=_\V{r}.\V{get}(\V{i}+\N{1});}}
\L{\LB{}\Tab{12}{\K{else}}\Tab{36}{\V{nxtNode}_=_\K{null};}}
\L{\LB{}\Tab{12}{\K{if}(\V{i}\>\N{0})}\Tab{36}{\V{prvNode}_=_\V{r}.\V{get}(\V{i}\-\N{1});}}
\L{\LB{}\Tab{12}{\K{else}}\Tab{36}{\V{prvNode}_=_\K{null};}}
\L{\LB{}\Tab{12}{\V{curNode}_=_\V{r}.\V{get}(\V{i});}}
\L{\LB{}\Tab{12}{}}
\L{\LB{}\Tab{12}{\K{double}_\V{angle}_=_\-\N{1};}}
\L{\LB{}\Tab{12}{\K{if}(\V{nxtNode}!=\K{null}_\&\&_\V{prvNode}!=\K{null})_\{}}
\L{\LB{}\Tab{16}{\V{Point}_\V{c}_=_\V{prvNode}.\V{location}();}}
\L{\LB{}\Tab{16}{\V{Point}_\V{p}_=_\V{curNode}.\V{location}();}}
\L{\LB{}\Tab{16}{\V{Point}_\V{n}_=_\V{nxtNode}.\V{location}();}}
\L{\LB{}\Tab{16}{}}
\L{\LB{}\Tab{16}{\V{Point}_\V{u},_\V{v};}\Tab{29}{\C{}//line_vectors\CE{}}}
\L{\LB{}\Tab{16}{\V{u}_=_\K{new}_\V{Point}((\K{int})(\V{c}.\V{getX}()\-\V{p}.\V{getX}()),(\K{int})(\V{c}.\V{getY}()\-\V{p}.\V{getY}()));}}
\L{\LB{}\Tab{16}{\V{v}_=_\K{new}_\V{Point}((\K{int})(\V{n}.\V{getX}()\-\V{p}.\V{getX}()),(\K{int})(\V{n}.\V{getY}()\-\V{p}.\V{getY}()));}}
\L{\LB{}\Tab{16}{}}
\L{\LB{}\Tab{16}{\K{double}_\V{dp},_\V{mu},_\V{mv};}\Tab{36}{\C{}//dot_product,_magnitude_u,_magnitude_v\CE{}}}
\L{\LB{}\Tab{16}{\V{dp}_=_(\V{u}.\V{getX}()*\V{v}.\V{getX}())_+_(\V{u}.\V{getY}()*\V{v}.\V{getY}());}}
\L{\LB{}\Tab{16}{\V{mu}_=_\V{Math}.\V{sqrt}(\V{Math}.\V{pow}(\V{u}.\V{getX}(),\N{2})+\V{Math}.\V{pow}(\V{u}.\V{getY}(),\N{2}));}}
\L{\LB{}\Tab{16}{\V{mv}_=_\V{Math}.\V{sqrt}(\V{Math}.\V{pow}(\V{v}.\V{getX}(),\N{2})+\V{Math}.\V{pow}(\V{v}.\V{getY}(),\N{2}));}}
\L{\LB{}\Tab{16}{}}
\L{\LB{}\Tab{16}{\V{angle}_=_\V{Math}.\V{toDegrees}(\V{Math}.\V{acos}(_\V{dp}_/_(\V{mu}*\V{mv})_));}}
\L{\LB{}\Tab{12}{\}}}
\L{\LB{}\Tab{12}{}}
\L{\LB{}\Tab{12}{\C{}//_TODO:_Angle_isn{'}t_enough_to_determine_turning_direction.\CE{}}}
\L{\LB{}\Tab{12}{}}
\L{\LB{}\Tab{12}{\C{}//directionBox.append(String.valueOf(r.get(i).id()));\CE{}}}
\L{\LB{}\Tab{12}{\C{}/*if(angle_\>_85_\&\&_angle_\<_95)_\{}}
\L{\LB{}\Tab{16}{directionBox.append(\3Continue\2n\3);}}
\L{\LB{}\Tab{16}{continue;}}
\L{\LB{}\Tab{12}{\}*/\CE{}}}
\L{\LB{}\Tab{12}{\V{directionBox}.\V{append}(\V{curNode}.\V{description}());}\Tab{63}{\C{}//_+_\3\2t\3+angle\CE{}}}
\L{\LB{}\Tab{12}{\K{if}(\V{i}==\V{curDirectionNumber})_\{}}
\L{\LB{}\Tab{16}{\V{directionBox}.\V{append}(\S{}\3\2t\<\<\<\3\SE{});}}
\L{\LB{}\Tab{16}{\K{if}(\V{curNode}.\V{map}().\V{compareTo}(\V{curMap})!=\N{0})_\{}}
\L{\LB{}\Tab{20}{\V{curMap}_=_\V{curNode}.\V{map}();}}
\L{\LB{}\Tab{20}{\V{router}.\V{setMap}(\V{curMap});}}
\L{\LB{}\Tab{20}{\V{router}.\V{update}();}}
\L{\LB{}\Tab{20}{\V{mm}_=_\V{router}.\V{getMapManager}();}}
\L{\LB{}\Tab{16}{\}}}
\L{\LB{}\Tab{12}{\}}}
\L{\LB{}\Tab{12}{\V{directionBox}.\V{append}(\S{}\3\2n\3\SE{});}}
\L{\LB{}\Tab{8}{\}}}
\L{\LB{}\Tab{4}{\}}}
\L{\LB{}\Tab{4}{}}
\L{\LB{}\Tab{4}{}}
\L{\LB{}\Tab{4}{}}
\L{\LB{}\Tab{4}{\C{}/**}}
\L{\LB{}\Tab{5}{*_Listener_methods_for_button_actions}}
\L{\LB{}\Tab{5}{*/\CE{}}}
\L{\LB{}\Tab{4}{\K{private}_\K{class}_\V{ButtonMethods}_\K{implements}_\V{ActionListener}_\{}}
\index{actionPerformed}\Proc{actionPerformed}\L{\LB{}\Tab{8}{\K{public}_\K{void}_\V{actionPerformed}(\V{ActionEvent}_\V{e})_\{}}
\L{\LB{}\Tab{12}{\K{if}(\V{e}.\V{getSource}()_==_\V{bNext})_\{}}
\L{\LB{}\Tab{16}{\K{if}(\V{curDirection}\<\V{r}.\V{size}()\-\N{1})}}
\L{\LB{}\Tab{20}{\V{curDirection}++;}}
\L{\LB{}\Tab{16}{\V{showDirections}(\V{curDirection});}}
\L{\LB{}\Tab{16}{\V{mm}.\V{centerAroundPoint}(\V{r}.\V{get}(\V{curDirection}).\V{location}());}}
\L{\LB{}\Tab{12}{\}}}
\L{\LB{}\Tab{12}{\K{if}(\V{e}.\V{getSource}()_==_\V{bPrevious})_\{}}
\L{\LB{}\Tab{16}{\K{if}(\V{curDirection}\>\N{0})}}
\L{\LB{}\Tab{20}{\V{curDirection}\-\-;}}
\L{\LB{}\Tab{16}{\V{showDirections}(\V{curDirection});}}
\L{\LB{}\Tab{16}{\V{mm}.\V{centerAroundPoint}(\V{r}.\V{get}(\V{curDirection}).\V{location}());}}
\L{\LB{}\Tab{12}{\}}}
\L{\LB{}\Tab{8}{\}}}
\L{\LB{}\Tab{4}{\}}\Tab{9}{}}
\L{\LB{}\Tab{4}{}}
\L{\LB{\}}}
